<?php
	// server should keep session data for AT LEAST 1 hour
	ini_set('session.gc_maxlifetime', 7200);

	// each client should remember their session id for EXACTLY 1 hour
	session_set_cookie_params(7200);
	
	date_default_timezone_set("Asia/Bangkok");
	
	session_start();
	set_time_limit(600);
	ini_set('max_execution_time',600);
	
	#################################################################################
	if(!defined('DIR_WS_USER'))
	{
		define('DIR_WS_USER', '');
	}
	define('DIR_WS_IMAGES', DIR_WS_USER.'images/');	
	define('DIR_WS_USER_INCLUDES', DIR_WS_USER . 'includes/');
	define('DIR_WS_USER_LIBRARIES', DIR_WS_USER_INCLUDES . 'classes/libraries/');
	define('DIR_WS_USER_HELPERS', DIR_WS_USER_INCLUDES . 'classes/helpers/');
	#################################################################################	
	
	require_once(DIR_WS_USER_INCLUDES.'functions/common.php');
	require_once(DIR_WS_USER_INCLUDES.'config.php');	
	if($db_type == "mysql")
	{
		require_once(DIR_WS_USER_LIBRARIES.'clsDBmysql.php');
		require_once(DIR_WS_USER_LIBRARIES.'clsPaging.php');
	}
	else
	{
		require_once(DIR_WS_USER_LIBRARIES.'clsDBmssql.php');
	}
	require_once(DIR_WS_USER_LIBRARIES.'clsDate.php');
	require_once(DIR_WS_USER_LIBRARIES.'clsErrorMessages.php');
	require_once(DIR_WS_USER_LIBRARIES.'clsOptions.php');
	require_once(DIR_WS_USER_LIBRARIES.'clsEncrypt.php');
	require_once(DIR_WS_USER_LIBRARIES.'clsMobileDetect.php');
    
	define('MAXROWS', 20);
	define('MAXPAGES', 5);
	
	if($db_type == "mysql")
	{
		$db_mysql = new DBmysql();
		$GLOBALS['db_mysql'] = $db_mysql;
	}
	else
	{
		$db_mysql = new DBmssql();
		$GLOBALS['db_mysql'] = $db_mysql;
	}
	
	$current_url = selfURL();
	$source = (isset($_GET['source']))?$_GET['source']:urlencode($current_url);
	
	define('CURRENT_URL', $current_url);
	define('SOURCE', $source); 	
	//define('SMTP',"smtp.sendgrid.net");
	//define('SMTP_USERNAME',"bliss");
	//define('SMTP_PASSWORD',"blissinteractive");
	################################# Define configuration [Start] ####################
	$arr_configuration =  $db_mysql->get_array("Select * From configuration");
	foreach($arr_configuration as $row)
	{
		if(!defined($row['configuration_key']))
			define($row['configuration_key'], $row['configuration_value']);
	}	
	$projectName = preg_replace('/[^a-zA-Z0-9]/', '', PROJECT_NAME);
	define('LOGIN_SESSION_NAME', 'loginInfo_' . $projectName);
	define('SESSION_ERRORS_NAME', 'SessionErrorName_' . $projectName);
	$user_id_login = get_loginInfo(LOGIN_SESSION_NAME, "user_id");
	$user_lang_login = get_loginInfo(LOGIN_SESSION_NAME, "lang");
	$user_type_login = get_loginInfo(LOGIN_SESSION_NAME, "user_type");
	$fullname_login = get_loginInfo(LOGIN_SESSION_NAME, "full_name");
	
	$module = setVar("module","");
	
	require_once(DIR_WS_USER_INCLUDES.'chksession.php');
	############################## Get content pages [Start] ############################
	$modulePath = "modules/home.php";
	if($module != "")
	{
		$modulePath = "modules/" . $module . ".php";	
		if(!file_exists($modulePath))
		{
			$modulePath = "modules/home.php"; 
			$module = "home";
		}
	}
	else
	{
		$module = "home";
		$modulePath = "modules/home.php"; 
	}
	############################## Get content pages [End] ############################
	############################## Languages [Start] ############################
	$lang = "en";
	############################## Languages [End] ############################
	
	############################## Device detection [Start] ############################
	$clsMobileDetect = new clsMobileDetect();
	$isMobile = FALSE;
	$isIpad = FALSE;
	$isTablet = FALSE;
	if($clsMobileDetect->isMobile())
	{
		$GLOBALS['isMobile'] = TRUE;
		if($clsMobileDetect->isIpad())
		{
			$GLOBALS['isIpad'] = TRUE;
			$GLOBALS['isMobile'] = false;
		}
		else if($clsMobileDetect->isTablet())
		{
			$GLOBALS['isTablet'] = TRUE;
			$GLOBALS['isMobile'] = false;		
		}
	}
	
	$device_info = "Desktop";
	if($isIpad == true)
		$device_info = "Ipad";
	else if($isTablet == true)
		$device_info = "Tablet";
	else if($isMobile == true)
		 $device_info = "Mobile";
	
	define('DEVICE_INFO', $device_info);
	############################## Device detection [END] ############################
?>